var vote= new Vue({
    el : '#Votelist',
    data:{
        userId : $("#id").val(),
        xiangmuId:'',
        xiangmu : {},
        votelist:[],
        show : false,
        total:0,
        tongyishu:0,
        butongyishu:0
    },
    created : function() {
        var _this = this;

        $(".nav navbar-nav li").removeClass("active");
        $("#nav_biaojue").addClass("active");
        _this.findIsacticed();

    },
    methods : {

        findIsacticed:function (){
            var _this = this;
            layer.open({type:3});
            $.post('/xiangmu/getIsactivedxiangmu', {
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        var data = ppData.resultContent;
                        _this.xiangmu = data;
                        _this.xiangmuId=_this.xiangmu.xiangmuid;
                        _this.findBiaojuelist();

                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },

        findBiaojuelist:function (){
            var _this = this;
            layer.open({type:3});
            $.post("/yinjin/findBiaojuelist",{
                xiangmuid :_this.xiangmuId,
                userid :_this.userId,
                rdm : Math.random()
            },function(ppData){
                layer.closeAll("loading");
                if (ppData != null){
                    if(ppData.result == "1"){
                        var data=ppData.resultContent;

                        if(data.length > 0){
                            _this.show = true;
                            _this.votelist=data;
                            _this.total=data.length;
                            _this.getYinjinResultCount();
                        }else {
                            _this.show = false;
                        }

                    }else{
                        layer.alert(ppData.message);
                    }
                }

            },"json");
        },

        getYinjinResultCount:function (){
            var _this = this;
            layer.open({type:3});
            $.post('/jieguo/getYinjinResultCount', {
                xiangmuid :_this.xiangmuId,
                userid :_this.userId,
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        var data = ppData.resultContent;
                        _this.tongyishu=data.tongyiShu;
                        _this.butongyishu=data.butongyiShu;
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },

        toVote:function (ppId,ppIstongyi) {

            var _this = this;
            layer.open({type: 3});
            $.post('/jieguo/toupiao', {
                id: ppId,
                userid: _this.userId,
                result: ppIstongyi,
                rdm: Math.random()
            }, function (ppData) {
                layer.closeAll("loading");
                if (ppData != null) {
                    if (ppData.result == "1") {
                        _this.getYinjinResultCount();
                        if (ppIstongyi == 1) {
                            $("#jieguo" + ppId).html("<span style=\"color:green\">同意</span>");
                        }
                        if (ppIstongyi == 0) {
                            $("#jieguo" + ppId).html("<span style=\"color:red\">不同意</span>");
                        }
                    } else {
                        layer.alert(ppData.message);
                    }
                }
            }, "json");
        },

        toVoteAll:function (ppresult){

            var _this = this;
            var mmMessage="";
            if("0"==ppresult){
                mmMessage="确定全部不同意当前表决项？";
            }else if("1"==ppresult){
                mmMessage="确定全部同意当前表决项？";
            }
            layer.confirm(mmMessage,{
                btn : ['是','否']
            },function(){
                layer.open({type:3});

                $.post("/jieguo/toupiao_all", {
                    xiangmuid :_this.xiangmuId,
                    userid :_this.userId,
                    result:ppresult,
                    random : Math.random()
                }, function(ppData) {
                    if (ppData != null) {
                        layer.closeAll("loading");

                        if(ppData.result != "1"){
                            layer.alert(ppData.message);
                        }else{
                            layer.open({
                                time:1000,
                                btn:[],
                                content:"操作成功!",
                            });
                            window.location.reload();
                            //_this.getBaofeiResultCount();
                            // _this.findBiaojuelist();
                        }
                    }
                },"json");
            })
        },
        toshowDetail :function (ppdetailId){
            layer.alert(ppdetailId);
        },



    }
})